// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Vuex from 'vuex'

import VueLazyload from 'vue-lazyload'
import InfiniteScroll from 'vue-infinite-scroll'

import {currency} from './util/currency'

// 懒加载插件
// or with options
Vue.use(VueLazyload, {
  // preLoad: 1.3,
  // error: 'dist/error.png',
  loading: '/static/images/loading/loading-bars.svg',
  // attempt: 1
})
// 无限滚动插件
Vue.use(InfiniteScroll)
// 定义全局过滤器(加括号是方法的调用，不加括号是动态的方法)
Vue.filter('currency', currency);

// vuex
Vue.use(Vuex)

Vue.config.productionTip = false

/* eslint-disable no-new */
const store = new Vuex.Store({
  state:{
    nickName:'',
    cartCount:0
  },
  mutations:{
    updateUserInfo(state, nickName){
      state.nickName = nickName;
    },
    updateCartCount(state, cartCount){
      state.cartCount += cartCount;
    },
    // 初始化购物车
    initCartCount(state, cartCount){
      state.cartCount = cartCount;
    }
  }
})

new Vue({
  el: '#app',
  store,
  router,
  components: { App },
  template: '<App/>'
});

